<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link rel="stylesheet" type="text/css" href="style.css" />
<title>CorkBoard It!</title>
</head>

<body>

<?php
	session_start();
	
	$host="localhost";
	$username="root";
	$password="";
	$database="cs4400_group17";

	mysql_connect($host,$username,$password);
	@mysql_select_db($database) or die( "Unable to select database");
	
	$username = $_SESSION['userName'];
	$useremail = $_SESSION['userEmail'];
	$pushpinEmail = $_GET['pushpinEmail'];
	$pushpinTitle = $_GET['pushpinTitle'];
	$pushpinURL = $_GET['pushpinURL'];
	$pushpinDateTime = $_GET['pushpinDateTime'];
	$pushpinDescription = $_GET['pushpinDescription'];
	
	$sql = "SELECT Name from user WHERE Email='$pushpinEmail'";
	$result = mysql_query($sql);
	$row = mysql_fetch_array($result);
	$pushpinOwnerName = $row[0];
	
	$sql = "SELECT Tag FROM tags WHERE URL='$pushpinURL'";
	$result = mysql_query($sql);
	
?>

<div id="masthead">
	<h1>CorkBoard<span style="color:red;">It</span></h1>
	<p style="color:orange;margin-top:-10px"><b>Explore. Share. Inspire.</b></p>
</div>


<div id="container">
	<div id="page_content">
		<h1>Pushpin Owner: <?php echo $pushpinOwnerName. ' (' .$pushpinEmail . ')';?></h1>
		<h2>Pushpin Title: <?php echo $pushpinTitle?></h2>
		<img src="<?php echo $pushpinURL; ?>"/>
		<h2>Date: <?php echo $pushpinDateTime?></h2>
		<p>Description: <strong><?php echo $pushpinDescription?></strong></p>
		<p>Tags: <strong><?php while($rows = mysql_fetch_array($result)){
				echo $rows[0].', ';
			}
			$count=mysql_num_rows($result);
			if($count < 1){
				echo "This Pushpin has no tags";
			}
		?></strong></p>
		
		<p>The following users like this: <strong><?php 
			$sql = "SELECT Email FROM userlikes WHERE PushPinURL='$pushpinURL'";
			$result = mysql_query($sql);
			while($rows = mysql_fetch_array($result)){
				echo $rows[0].', ';
			}
			$count=mysql_num_rows($result);
			if($count < 1){
				echo "No one :(";
			}
		?></strong></p>
		
		<h2>Comments:</h2>
		<p>
			<form action="makecomment.php" method="post">
				<input type="text" name="Comment" size="100" />
				<input type="hidden" name="OwnerEmail" value="<?php echo $pushpinEmail; ?>">
				<input type="hidden" name="corkTitle" value="<?php echo $pushpinTitle;?>">
				<input type="hidden" name="ppURL" value="<?php echo $pushpinURL;?>">
				<input type="submit" value="Comment">
			</form>
		</p>
		
		<BR>
		<?php
			$sql = "SELECT CommenterEmail,Text,DateTime FROM comments WHERE PushPinURL='$pushpinURL'";
			$result = mysql_query($sql);
			while($rows = mysql_fetch_array($result)){
		?>
		<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
			<tr>
				<td>
					<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
						<tr>
							<td>Author</td>
							<td>:</td>
							<td><?php 
								$commenterEmail = $rows['CommenterEmail'];
								$query = "SELECT Name from user WHERE Email='$commenterEmail'";
								$result2 = mysql_query($query);
								$row2 = mysql_fetch_array($result2);
								echo $row2[0] . ' (' . $rows['CommenterEmail'] . ')';
							?></td>
						</tr>
						<tr>
							<td>Comment</td>
							<td>:</td>
							<td><?php echo $rows['Text']; ?></td>
						</tr>
						<tr>
							<td width="117">Date:</td>
							<td width="14">:</td>
							<td width="357"><?php echo $rows['DateTime']; ?></td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		<BR>
		<?php
			}
			$count=mysql_num_rows($result);
			if($count < 1){
				echo "<p>No Comments for this Pushpin :(</p>";
			}
		?>
	</div>
	
	<?php 
		echo "<a href='like.php?corkTitle=$pushpinTitle&OwnerEmail=$pushpinEmail&ppURL=$pushpinURL&ppDT=$pushpinDateTime&ppD=$pushpinDescription'> Like Pushpin </a>";
	?>
</div>

<div id="footer">
	<form name = "input" action = "home.php" method = "post">
		<input type="submit" value="Back to Home" name="backtohome"/>
	</form>
</div>

</body>

</html>
